package file;

import java.awt.Point;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

public class XmlFactory {
	CategoryList docs;

	public Document getXML() {
		List<File> texs = Texs.getTexs().getTexList();
		docs = analyseDocs(texs);
		return buildXML();
	}

	private CategoryList analyseDocs(List<File> texs) {
		CategoryList list = new CategoryList();
		for (File file : texs) {
			list.addDoc(new Doc(file));
		}
		return list;
	}

	private Document buildXML() {
		Document document = DocumentHelper.createDocument();
		Element root = document.addElement("docs");
		root.addElement("title").addText("project name");
		for (Category category : docs.getCategorys()) {
			Element element = root.addElement("category").addAttribute("name",
					category.getName());
			for (Doc doc : category.getDocs()) {
				element.addElement("doc").addAttribute("name", doc.getName())
						.addAttribute("path", doc.getPath());
			}
		}
		return document;
	}
}
